********************************************************************************
******"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*******
********************************************************************************

********************************************************************************
********************************************************************************
**********************************2019******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global ec0 "dT1e10 dT2e10 dT3e10 dT4e10 dT5e10 dT7e10 dT8e10 dT9e10 dT10e10 dT11e10 dT12e10"
global ec1 "dT1e11 dT2e11 dT3e11 dT4e11 dT5e11 dT7e11 dT8e11 dT9e11 dT10e11 dT11e11 dT12e11"
global ec4 "dT1e14 dT2e14 dT3e14 dT4e14 dT5e14 dT7e14 dT8e14 dT9e14 dT10e14 dT11e14 dT12e14"
global controls "lncrefin dT*exlnassets dT*excashas"
global regcommands ", pool(5) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

clear *
**# Bookmark (input)
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans2019, case(lower)
run RO_creditregister tm(2019m2) tm(2020m2) 0
keep bankid borrowerid time disbur

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2019, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2019m8, keepus(e10 e14 e11 exlnassets excashas)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2019, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2019m3)&time<=tm(2020m2)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

run RO_tdummies 2019 12
run RO_tdintera 12 "e10 e14 e11 exlnassets excashas"

**# Bookmark (output - column 1 - IA and IB)
est clear
cd $outputdirectory
reghdfe $y $ec4 $ec1 $controls $regcommands
est save TABIA_C1a1b
foreach x of numlist 7 8 9 10 11 12 {
lincom dT`x'e14-(dT`x'e11-((dT1e11+dT2e11+dT3e11+dT4e11+dT5e11)/5))
if `x'==7 {
matrix TABIA_test1a1b = (r(estimate),r(p),r(se))
}
else {
matrix TABIA_test1a1b = (TABIA_test1a1b \ r(estimate),r(p),r(se))
}
}
matrix colnames TABIA_test1a1b = coef pvalue se
matrix rownames TABIA_test1a1b = t7 t8 t9 t10 t11 t12
reghdfe $y $ec0 $ec4  $controls $regcommands
est save TABIB_C1a1b
matsave TABIA_test1a1b, replace dropall
cd ..

********************************************************************************
********************************************************************************
**********************************2015******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global ec0 "dT1e10 dT2e10 dT3e10 dT4e10 dT5e10 dT7e10 dT8e10 dT9e10 dT10e10 dT11e10 dT12e10"
global ec3 "dT1e13 dT2e13 dT3e13 dT4e13 dT5e13 dT7e13 dT8e13 dT9e13 dT10e13 dT11e13 dT12e13"
global ec5 "dT1e15 dT2e15 dT3e15 dT4e15 dT5e15 dT7e15 dT8e15 dT9e15 dT10e15 dT11e15 dT12e15"
global controls "lncrefin dT*exlnassets dT*excashas"
global regcommands ", pool(5) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

**# Bookmark (input)
clear*
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans, case(lower)
run RO_creditregister tm(2014m6) tm(2015m6) 0
keep bankid borrowerid time disbur

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2015, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m12, keepus(e10 e13 e15 exlnassets excashas)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2015, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2014m7)&time<=tm(2015m6)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

run RO_tdummies 2015 12
run RO_tdintera 12 "e10 e13 e15 exlnassets excashas"

**# Bookmark (output - column 2 - IA and IB)
est clear
cd $outputdirectory
reghdfe $y $ec3 $ec5 $controls $regcommands
est save TABIA_C2a2b
foreach x of numlist 7 8 9 10 11 12 {
lincom dT`x'e13-(dT`x'e15-((dT1e15+dT2e15+dT3e15+dT4e15+dT5e15)/5))
if `x'==7 {
matrix TABIA_test2a2b = (r(estimate),r(p),r(se))
}
else {
matrix TABIA_test2a2b = (TABIA_test2a2b \ r(estimate),r(p),r(se))
}
}
matrix colnames TABIA_test2a2b = coef pvalue se
matrix rownames TABIA_test2a2b = t7 t8 t9 t10 t11 t12
reghdfe $y $ec0 $ec3 $controls $regcommands
est save TABIB_C2a2b
matsave TABIA_test2a2b, replace dropall

cd ..

